package com.chuang.bootplus.service.impl;

import com.chuang.bootplus.base.utils.ApiResponse;
import com.chuang.bootplus.base.utils.BeanUtil;
import com.chuang.bootplus.entity.Message;
import com.chuang.bootplus.mapper.MessageMapper;
import com.chuang.bootplus.po.MessagePO;
import com.chuang.bootplus.service.MessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chuang.bootplus.vo.MessageVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-11-22
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    @Override
    public ApiResponse<Void> send(MessagePO po) {
        save(BeanUtil.beanA2beanB(po,Message.class));
        return  new ApiResponse<>();
    }

    @Override
    public ApiResponse<MessageVO> listAll() {
        List<Message> list = list();
        List<MessageVO> messageVOS = BeanUtil.listA2ListB(list, MessageVO.class);
        return new ApiResponse<>(messageVOS);
    }
}
